<?php
namespace Modules;

use Admin\Models\user\XhsysUserstud;
use Admin\Models\user\XhsysUser;
use Helpers\XhException;

class Stud
{

    /**
     * 设置学生教师子女属性
     *
     * @param $studId
     * @param $tchChildLevel
     * @param $iDevCost
     * @param $iSerCost
     *
     * @return bool
     *
     * @throws XhException
     * create by gby 20180801
     */
    public static function setTchChild($studId, $tchChildLevel, $iDevCost = '', $iSerCost = '')
    {
        try {
            $studInfo = XhsysUserstud::findFirst($studId);
            if (!$studInfo) {
                $studInfo = new XhsysUserstud([
                    'iUserId' => $studId
                ]);
            }
            $studInfo->iTchChild = $tchChildLevel;
            $studInfo->iDevCost = $iDevCost;
            $studInfo->iSerCost = $iSerCost;
            if (!$studInfo->save()) {
                throw new XhException($studInfo->getError());
            }
            return true;
        } catch (XhException $e) {
            throw new XhException('操作失败', $e->getMessage());
        }
    }

    /**
     * 设置贫困生属性
     *
     * @param $studId
     * @param $iPoorLevel
     * @return bool
     *
     * @throws XhException
     * create by gby 20180801
     */
    public static function setPoorLevel($studId, $iPoorLevel)
    {
        try {
            $studInfo = XhsysUser::findFirst($studId);
            if (!$studInfo) {
                return false;
            }
            $studInfo->iPoorLevel  = $iPoorLevel;
            if (!$studInfo->save()) {
                throw new XhException($studInfo->getError());
            }
            return true;
        } catch (XhException $e) {
            throw new XhException('操作失败', $e->getMessage());
        }
    }
}
